#include "include/controller.h"

Controller::Controller(QWidget *parent) :
    QWidget(parent)
{
}

void Controller::addView(View *v)
{
    view = v;

    QObject::connect(view->quit, SIGNAL(clicked()), view->view, SLOT(close()));

    QObject::connect(view->grid, SIGNAL(clicked()), this, SLOT(sendGridCoordinates()));
    QObject::connect(this, SIGNAL(createGridCoordinates(int, int)), view, SLOT(updateLocation(int, int)));
}

void Controller::sendGridCoordinates()
{
    int x = QCursor::pos().x() - view->view->window()->pos().x() - view->grid->pos().x() - 9;
    int y = QCursor::pos().y() - view->view->window()->pos().y() - view->grid->pos().y() - 29;

    emit createGridCoordinates(x, y);
}
